from sqlalchemy import Column, Integer, String, Text, JSON, DateTime, func, Boolean
from sqlalchemy.dialects.mysql import LONGTEXT
from models import Base


class Task(Base):
    __tablename__ = "tasks"
    id = Column(Integer, primary_key=True)

    script = Column(Integer, nullable=False)
    name = Column(String(32), unique=True, index=True)
    cron = Column(String(32), nullable=False)
    status = Column(Integer)
    args = Column(JSON)
    recount = Column(Integer)
    last_status = Column(Integer)
    next_time = Column(DateTime)
    enable = Column(Boolean, nullable=False)
    username = Column(String(32), nullable=False)
    delay =  Column(String(32), default='')
    c_time = Column(DateTime, server_default=func.now())
    m_time = Column(DateTime, server_default=func.now())


class TaskHistory(Base):
    __tablename__ = "task_histories"
    id = Column(Integer, primary_key=True)

    task_id = Column(Integer, nullable=False)
    task_name = Column(String(32), nullable=False)
    script_id = Column(String(64), nullable=False)
    script_name = Column(String(64), nullable=False)
    create_time = Column(DateTime, nullable=False)
    username = Column(String(32), nullable=False)
    status = Column(Integer, nullable=False)
    content = Column(LONGTEXT, nullable=False)

